import unittest
from selenium import webdriver
import time
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.by import By


class jiuxian3(unittest.TestCase):

    def setUp(self):
        # 打开edge浏览器
        self.driver = webdriver.Edge()
        #  打开酒仙网
        self.driver.get('https://www.jiuxian.com/')
        # 窗口最大化
        self.driver.maximize_window()

    def tearDown(self):
        # 关闭浏览器
        self.driver.close()
        print('结束')

    def test_01(self):
        # 点击请登录,class定位
        self.driver.find_element(By.CLASS_NAME, 'headerLogin').click()
        time.sleep(2)
        # 输入账号，id定位
        self.driver.find_element(By.ID, 'userName').send_keys('15523615751')
        # 输入密码，xpath定位
        self.driver.find_element(By.XPATH, '//*[@id="password"]').send_keys('lj070130.')
        time.sleep(15)
        # 点击登录，name定位
        self.driver.find_element(By.NAME, 'bi_Usuallogin').click()
        time.sleep(2)
        # 点击弹窗确定，xpath定位
        self.driver.find_element(By.XPATH, '/html/body/div/div[4]/div[2]/div[2]/a').click()
        time.sleep(2)
        # 断言登录返回的用户名
        dy = self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div[1]/div/p/span').text
        print(dy)
        self.assertIn('jxw862943923', dy)
        # 点击我的酒仙
        self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div[2]/ul/li[1]/div[1]/a').click()
        time.sleep(2)
        # 切窗口
        self.driver.switch_to.window(self.driver.window_handles[-1])
        time.sleep(2)
        # 关闭弹窗
        self.driver.find_element(By.CLASS_NAME, 'uGuideClose').click()
        time.sleep(2)
        # 下滑
        self.driver.execute_script('window.scrollTo(0,800)')
        time.sleep(2)
        # 点击收货地址
        self.driver.find_element(By.XPATH, '/html/body/div[4]/div[1]/div[2]/div[4]/a[3]/span').click()
        time.sleep(2)
        # 文本断言，添加新地址
        dy2 = self.driver.find_element(By.CLASS_NAME,'ln_addressBoxTitL').text
        self.assertEqual('添加新地址', dy2)
        # 输入收货人
        self.driver.find_element(By.ID, 'people').send_keys('小六')
        time.sleep(2)
        # 选择地区
        province = Select(self.driver.find_element(By.NAME, 'province'))
        province.select_by_value('2')
        time.sleep(2)
        city = Select(self.driver.find_element(By.NAME, 'city'))
        city.select_by_value('52')
        time.sleep(2)
        district = Select(self.driver.find_element(By.NAME, 'district'))
        district.select_by_value('512')
        time.sleep(2)
        # 详细地址
        self.driver.find_element(By.ID, 'address').send_keys('水厂路小区')
        time.sleep(2)
        # 邮政编码
        self.driver.find_element(By.ID, 'zipcode').send_keys('100160')
        time.sleep(2)
        # 输入手机号
        self.driver.find_element(By.ID, 'iphone').send_keys('15523615751')
        time.sleep(2)
        # 点击提交
        self.driver.find_element(By.XPATH, '//*[@id="save"]').click()
        time.sleep(2)

